<tagLib name="html" />

<div id="answer-container" class="container">
    <div id="msg-container">
        <h2 class="error-tips"></h2>
    </div>
    <h2><a href="{$question.question_id|format_question_url=$question['title']}">{$question.title}</a></h2>
    <form id="answer-form" action="{:U('Answer/add')}" method="POST">
        <input id="qid" type="hidden" name="qid" value="{$question.question_id}" />
        <input id="type" type="hidden" name="type" value="{$type}" />
        <p><html:markitup id="answer-details" name="details" content="" /></p>
        <p id="answer-counter"></p>
        <volist name="teams" id="vo">
        <p><input id="my-team-{$vo.team_id}" <if condition="count($teams) gt 1">type="radio"<else/>type="checkbox"</if> name="team_id" value="{$vo.team_id}" <eq name="key" value="0">checked</eq> /><label for="my-team-{$vo.team_id}"> {$vo.label} </label></p>
        </volist>
        <p><input id="new-comment-alert" type="checkbox" name="new_comment_alert" value="1" <eq name="_user.new_comment_alert" value="1">checked</eq> /><label for="new-comment-alert"> {$Think.lang.new_comment_alert} </label></p>
        <eq name="captcha" value="1">
        <div class="captcha-container"><label for="verify">{$Think.lang.captcha}:</label><input id="verify" class="input verify" type="text" name="verify" value="" /><img class="captcha" src="{:U('Ajax/captcha')}" title="{$Think.lang.captcha_again}" onclick="reCaptcha(this);" /></div>
        </eq>
        <p><input id="answer-submit" class="button" type="button" value="{$Think.lang.post_answer}" /></p>
    </form>
</div>

<script type="text/javascript">
$(function(){
	
    var maxChars = {$_global.max_post_chars};
    $('#answer-details').artTxtCount($('#answer-counter'), maxChars);
    
    $('#answer-submit').click(function(){
        var url = $('#answer-form').attr('action');
        var redirect = $(location).attr('href');
        var data = {
            qid: $('#qid').val(),
            type: $('#type').val(),
            verify: $('#verify').val(),
            details: $('#answer-details').val(),
            team_id: $("input[name=team_id]:checked").val(),
            new_comment_alert: $("input[name=new_comment_alert]").attr('checked') ? 1 : 0
        };
        $.post(url, data, function(json){
            $('#msg-container').show();
            var json = eval('('+json+')');
            if(json.status == 0){
                $('#msg-container>h2').html(json.info);
                return false;
            }else{
                $('#msg-container>h2').attr('class','success-tips').html(json.info);
                $('#answer-submit').attr({disabled:true, class:'alt-button'});
                setTimeout(function(){
                    window.location.href = redirect;
                }, WAIT_TIME);
            }
        });
    })
});
</script>
